package io.finer.erp.jeecg.bas.service.impl;

import java.util.List;

import org.jeecg.common.constant.CacheConstant;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;

import io.finer.erp.jeecg.bas.dto.BasCustomerAddressDTO;
import io.finer.erp.jeecg.bas.entity.BasCustomerAddress;
import io.finer.erp.jeecg.bas.mapper.BasCustomerAddressMapper;
import io.finer.erp.jeecg.bas.service.IBasCustomerAddressService;

/**
 * @Description: 客户地址表
 * @Author: jeecg-boot
 * @Date:   2020-10-09
 * @Version: V1.0
 */
@Service
public class BasCustomerAddressServiceImpl extends ServiceImpl<BasCustomerAddressMapper, BasCustomerAddress> implements IBasCustomerAddressService {

	@Override
	public BasCustomerAddress getCustomAddress(String customId) {
		LambdaQueryWrapper<BasCustomerAddress> query = new LambdaQueryWrapper<>();
		query.eq(BasCustomerAddress::getCustomerId, customId);
		query.orderByDesc(BasCustomerAddress::getCreateTime);
		List<BasCustomerAddress> list = list(query);
		if(null != list && 0 != list.size()) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<BasCustomerAddress> getAddressByCustomerId(String name){

		return baseMapper.likeAddressByName(name);
	}
	@Override
	public List<BasCustomerAddress> selectAddressByCustomerId(String customerId){

		return baseMapper.getAddressBycustomerId(customerId);
	}

	@Override
	@Cacheable(value=CacheConstant.BAS_CUSTOMER_ADDRESS)
	public List<BasCustomerAddressDTO> getAddressByCustomerAll() {
		return baseMapper.getAddressByCustomerAll();
	}
}
